package com.acmetelecom.core;

import java.math.BigDecimal;

import com.acmetelecom.call.Call;
import com.acmetelecom.customer.Customer;

public class LineItem {
        private Call call;
        private BigDecimal callCost;

        public LineItem(Call call, BigDecimal callCost) {
            this.call = call;
            this.callCost = callCost;
        }

        public String date() {
            return call.date();
        }

        public Customer callee() {
            return call.callee();
        }

        public String durationMinutes() {
            return "" + call.durationSeconds() / 60 + ":" + String.format("%02d", call.durationSeconds() % 60);
        }

        @Override
		public String toString() {
			return "LineItem [call=" + call + ", callCost=" + callCost + "]";
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((call == null) ? 0 : call.hashCode());
			result = prime * result
					+ ((callCost == null) ? 0 : callCost.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			LineItem other = (LineItem) obj;
			if (call == null) {
				if (other.call != null)
					return false;
			} else if (!call.equals(other.call))
				return false;
			if (callCost == null) {
				if (other.callCost != null)
					return false;
			} else if (!callCost.equals(other.callCost))
				return false;
			return true;
		}

		public BigDecimal cost() {
            return callCost;
        }
    }